package com.entor.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.entor.model.Comment;
import com.entor.model.EduExam;
import com.entor.model.EduExamTitle;
import com.entor.model.EduExamTitleRelationse;
import com.entor.model.EduTitle;
import com.entor.service.EduExamService;
import com.entor.service.EduTitleService;
import com.entor.util.Msg;

@Controller
@RequestMapping("/test")
public class TestController extends BaseController{
	
	@Resource(name="eduTitleService")
	private EduTitleService ets;
	@Resource(name="eduExamService")
	private EduExamService ees;
 	
	
	@RequestMapping("/titleIndex")
	public String titleIndex(){
		return "/test/titleIndex";
	}
	@RequestMapping("/examCheck")
	public String examCheck(HttpServletRequest req){
		String examId = req.getParameter("examId");
		if(examId!=null){
			int eid = Integer.parseInt(examId);
			Map<String,List<EduTitle>> maps = ees.findExamTitleRelations(eid);
			req.setAttribute("maps", maps);
		}
		return "/test/examCheck";
	}
	
	@RequestMapping("/addOrEdit")
	public String addOrEdit(){
		return "/test/titleAddOrEdit";
	}
	
	@RequestMapping("/examIndex")
	public String examIndex(){
		return "/test/examIndex";
	}
	
	@RequestMapping("/examAddOrEdit")
	public String examAddOrEdit(){
		return "/test/examAddOrEdit";
	}
	
	@RequestMapping("/titleFind")	
	@ResponseBody
	public List<EduTitle> find(EduTitle t){
		return ets.find(t);
	}
	
	@RequestMapping("/titleAdd")
	@ResponseBody
	public Msg add(EduTitle t){
		return ets.add(t);
	}
	
	@RequestMapping("/titleEdit")
	@ResponseBody
	public Msg edit(EduTitle t){
		return ets.edit(t);
	}
	
	@RequestMapping("/examFind")
	@ResponseBody
	public List<EduExam> examFind(EduExam t){
		return ees.find(t);
	}
	
	@RequestMapping("/examAdd")
	@ResponseBody
	public Msg examAdd(EduExam t){
		return ees.add(t);
	}
	
	@RequestMapping("/randomCreate")
	@ResponseBody
	public List<List<EduExamTitle>> randomCreate(EduExamTitle eet){
		return ees.randomCreate(eet);
	}
	
	
	@RequestMapping("/gotoCreate")
	@ResponseBody
	public Msg gotoCreate(Comment c){
		return ees.gotoCreate(c.getCode());
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
